<!-- 公共文件 start -->
@extends('admin.public.base')
<!-- 公共文件 end -->
<style>
    table th {
        min-width: 10px !important;
    }
    .layui-card-header {
        padding-top: 10px !important;
    }
</style>
@section('content')
    <div class="x-nav">
    <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">销售管理</a>
        <a><cite>默认策略</cite></a>
    </span>
        <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
           onclick="location.reload()" title="刷新">
            <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
        </a>
    </div>
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    @if(!count($data))
                        <div class="layui-card-header">
                            <button class="layui-btn" onclick="xadmin.open('添加默认策略','/admin/sales/defaultStrategyAdd',1100,630)"><i class="layui-icon"></i>添加</button>
                        </div>
                    @endif
                    <div class="layui-card-body ">
                        <table class="layui-table layui-form" style="width: 100%">
                            <thead>
                            <tr>
                                <th>名称</th>
                                <th>说明</th>
                                <th>状态</th>
                                <th>操作</th>
                            </thead>
                            <tbody>
                                @if(count($data))
                                    <tr>
                                        <td>
                                            默认策略（所有商品默认使用此策略）
                                        </td>
                                        <td>
                                            任意商品满{{$data['goods_number']}}瓶
                                            @foreach($data['send_goods'] as $item)
                                                <br>
                                                送{{$item['number']}}个{{$item['goods_name']}}
                                            @endforeach
                                        </td>
                                        <td>
                                            <span style="color: #009688">正常</span>
                                        </td>
                                        <td class="td-manage" style="min-width: 140px">
                                            <button class="layui-btn layui-btn layui-btn-xs"  onclick="xadmin.open('编辑默认策略','/admin/sales/defaultStrategyEdit',1100,630)" ><i class="layui-icon">&#xe642;</i>编辑</button>
                                            <button class="layui-btn-danger layui-btn layui-btn-xs"  onclick="sales_del(this)" href="javascript:;" ><i class="layui-icon">&#xe640;</i>删除</button>
                                        </td>
                                    </tr>
                                @endif
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script>
        layui.use(['laydate', 'form'], function(){
            var form = layui.form;
        });

        // 删除
        function sales_del(obj){
            layer.confirm('确认要删除吗？',function(index){
                //发异步删除数据
                $.ajax({
                    type: 'POST',
                    url: '/admin/sales/defaultStrategyDel',
                    data: {},
                    dataType: 'json',
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                    },
                    success: function (data) {
                        if (data.code == 1) {
                            $(obj).parents("tr").remove();
                            layer.msg('已删除',{icon:1,time:2000});
                            window.location.reload();
                        } else {
                            layer.alert(data.msg, {icon: 7, time: 2000, closeBtn: false, btn: []});
                        }
                    },
                    error: function (xhr, type) {
                        alert('Ajax error!')
                    }
                });
            });
        }
    </script>
@endsection
